import {
  createInbizSchema,
  createBaseSchema,
  createValidatorSchema,
  createComponentStyleSchema,
  createDecoratorStyleSchema,
  createModelSchema,
  getDefalutDecoratorProps,
  createComponentLayout,
  createControllerSchema,
} from '@inbiz/setters';
import { createBehavior, createResource } from '@inbiz/core';
import { EformNumber as LocaleInput } from './locale';
import { getPlatform } from '@inbiz/utils';

export const defaultProps = {
  minLength: undefined,
  maxLength: undefined,
  defaultValueType: 'custom',
  defaultValue: '',
  placeholder: 'EformNumber.placeholder',
  precision: undefined,
  formatter: '',
  prefix: '',
  suffix: '',
  clearable: true,
};

export const EformNumber = createInbizSchema({
  attribute: {
    ...createBaseSchema({
      precision: {
        type: 'number',
        'x-decorator': 'FormItem',
        'x-component-props': {
          min: 0,
          precision: 0,
        },
        'x-component': 'NumberPicker',
      },
      defaultValue: {
        type: 'number',
        'x-decorator': 'FormItem',
        'x-component': 'NumberPicker',
      },
      placeholder: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'MultilingualInput',
      },
      formatter: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
      prefix: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
      },
      // suffix: {
      //   type: 'string',
      //   'x-decorator': 'FormItem',
      //   'x-component': 'Input',
      // },
      addonAfter: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
      },
      clearable: {
        type: 'boolean',
        'x-decorator': 'FormItem',
        'x-component': 'Switch',
        platform: 'wap',
      },
    }),
    ...createValidatorSchema(false, {
      // minimum: {
      //   type: 'number',
      //   'x-decorator': 'FormItem',
      //   'x-component': 'NumberPicker',
      //   platform: 'web',
      // },
      // maximum: {
      //   type: 'number',
      //   'x-decorator': 'FormItem',
      //   'x-component': 'NumberPicker',
      //   platform: 'web',
      // },
      'x-component-props': {
        type: 'object',
        properties: {
          minimum: {
            type: 'number',
            'x-decorator': 'FormItem',
            'x-component': 'NumberPicker',
            // platform: 'wap',
          },
          maximum: {
            type: 'number',
            'x-decorator': 'FormItem',
            'x-component': 'NumberPicker',
            // platform: 'wap',
          },
          maxLength: {
            type: 'number',
            'x-decorator': 'FormItem',
            'x-component-props': {
              min: 0,
              precision: 0,
            },
            'x-component': 'NumberPicker',
          },
        },
      },
    }),
  },
  style: {
    ...createComponentStyleSchema(),
    ...createComponentLayout(),
    ...createDecoratorStyleSchema(),
  },
  senior: {
    ...createModelSchema(),
    // ...createSoureSchema(),
  },
  controller:createControllerSchema({
    events: [
    {
      name: "onChange",
      label: "数据变更"
    }
  ],
  })
});

export const Resource = createResource({
  icon: 'EformNumber',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'number',
        title: {
          value: 'EformNumber.title',
          status: true,
        },
        'x-decorator': 'FormItem',
        'x-component': 'EformNumber',
        'x-component-props': defaultProps,
        'x-decorator-props': getDefalutDecoratorProps(getPlatform()),
      },
    },
  ],
});

export const Behavior = createBehavior({
  name: 'EformNumber',
  extends: ['Field'],
  selector: (node) => node.props?.['x-component'] === 'EformNumber',
  designerLocales: LocaleInput,
  designerProps: { propsSchema: EformNumber },
});
